package com.kws.merchant.controller;


import com.kws.merchant.domain.OperationTicket;
import com.kws.merchant.domain.OperationTicketFile;
import com.kws.merchant.domain.po.*;
import com.kws.merchant.domain.vo.WorkTickVo;
import com.kws.merchant.service.OperationTicketFileService;
import com.kws.merchant.service.OperationTicketService;
import com.kws.merchant.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;

/**
 * 运维-两票管理(OperationTicket)表控制层
 *
 * @author yxy
 * @since 2024-10-28 08:54:05
 */
@RestController
@Api(tags = "运维-两票管理(OperationTicket)")
@RequestMapping("operationTicket")
public class OperationTicketController {
    /**
     * 服务对象
     */
    @Resource
    private OperationTicketService operationTicketService;
    @Autowired
    private OperationTicketFileService operationTicketFileService;
 
    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<OperationTicket>> pageList(@RequestBody TicketPo ticketPo){
        return R.ok(operationTicketService.pageList(ticketPo));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<OperationTicket> detailById(@PathVariable Long id) {
        return R.ok(operationTicketService.detailById(id));
    }

    @PostMapping("/addWorkTicket")
    @ApiOperation(value = "新增工作票")
    public R addWorkTicket(@RequestBody WorkPo workPo) {
        return R.ok(operationTicketService.addWorkTicket(workPo));
    }

    @PostMapping("/addHandleTicket")
    @ApiOperation(value = "新增操作票")
    public R addHandleTicket(@RequestBody HandlePo handlePo) {
        return R.ok(operationTicketService.addHandleTicket(handlePo));
    }

    @PostMapping("/statistics")
    @ApiOperation(value = "数据统计")
    public R<WorkTickVo> statistics(@RequestParam(required = false) String dept, @RequestParam(required = false) String startTime, @RequestParam(required = false     ) String endTime) {
        return R.ok(operationTicketService.statistics(dept,startTime,endTime));
    }

    @PostMapping("uploadTickFile")
    @ApiOperation("上传两票文件--导入word新增数据")
    public R uploadTickFile(@ModelAttribute TickFilePo tickFilePo){
        return R.ok(operationTicketService.uploadTickFile(tickFilePo));
    }

    @PostMapping("downloadTickFile")
    @ApiOperation("下载两票文件")
    public R downloadTickFile(Long id, HttpServletResponse response){
        return R.ok(operationTicketService.downloadTickFile(id,response));
    }

    @PostMapping("uploadFile")
    @ApiOperation("操作-上传文件-改变状态为已处理")
    public R uploadFile(@RequestBody TicketStatus tickFilePo){
        return R.ok(operationTicketService.uploadFile(tickFilePo));
    }
    @GetMapping("cancellation/{id}")
    @ApiOperation("根据两票id作废两票")
    public R cancellation(@PathVariable Long id){
        return R.ok(operationTicketService.cancellation(id));
    }

}
